package com.missmess.opengldemo.util;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

/**
 * @author wl
 * @since 2016/10/20 14:11
 */

public class BufferUtils {

    public static FloatBuffer float2Buffer(float[] array) {
        ByteBuffer vbb = ByteBuffer.allocateDirect(array.length * 4);
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer buffer = vbb.asFloatBuffer();
        buffer.put(array);
        buffer.position(0);
        return buffer;
    }

    public static ShortBuffer short2Buffer(short[] array) {
        ByteBuffer vbb = ByteBuffer.allocateDirect(array.length * 2);
        vbb.order(ByteOrder.nativeOrder());
        ShortBuffer buffer = vbb.asShortBuffer();
        buffer.put(array);
        buffer.position(0);
        return buffer;
    }
}
